<div id="main">
    <div id="contents">

            <fieldset>
                <legend>
                    <label sid="changepassword.title1"></label>
                </legend>
                <div class="frame_tab_layer">
                    <table class="cmenutitle" width="100%" cellspacing="0" cellpadding="0" border="0">
                        <tbody>
                        <tr id="tr51">
                            <td class="frame_tab_left">
                                <label sid="changepassword.td1"></label>
                            </td>
                            <td id="td51" class="frame_tab_right">
                                <input id="changepwd" type="password" maxlength="17" size="15" name="id51">
                            </td>
                        </tr>
                        <tr id="tr0">
                            <td class="frame_tab_left">
                                <label sid="changepassword.td2"></label>
                            </td>
                            <td id="td0" class="frame_tab_right">
                                <input id="confirmpwd" type="password" maxlength="17" size="15" name="id0">
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">&nbsp;</td>
                        </tr>
                        <tr>
                            <td class="frame_tab_center" colspan="2">
                                <input class="button" type="button" name="id911" sid="sbutton.save">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </fieldset>
            <fieldset>
                <legend>
                    <label sid="changepassword.title3"></label>
                </legend>
                <div class="frame_tab_layer">
                    <table class="cmenutitle" width="100%" cellspacing="0" cellpadding="0" border="0">
                        <tbody>
                        <tr id="tr186">
                            <td class="frame_tab_left">
                                <label sid="changepassword.td3"></label>
                            </td>
                            <td id="td186" class="frame_tab_right">
                                <input type="text" maxlength="17" size="15" name="id186" id="id186">
                                <label sid="changepassword.td4"></label>
                                <span class="x-form-tip" id="id186Tip"></span>

                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">&nbsp;</td>
                        </tr>
                        <tr>
                            <td class="frame_tab_center" colspan="2">
                                <input class="button" type="button" name="id913" sid="sbutton.save" id="submit">
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </fieldset>

    </div>
</div><br>
<div id="helpContainer">
    <div id="help">
        <div>
            <h2>
                <label sid="share.help"></label>
            </h2>
        </div>
        <div id="helpBody">
            <dl>
                <dt class="term">
                    <label sid="modifyPwd.titlel"></label>
                </dt>
                <dd class="definition">
                    <label sid="modifyPwd.sp1"></label>
                </dd>
                <dt class="term">
                    <label sid="modifyPwd.title2"></label>
                </dt>
                <dd class="definition">
                    <label sid="modifyPwd.sp2"></label>
                </dd>
            </dl>
        </div>
    </div>
</div>
<script type="text/javascript">

    $.formValidator.initConfig({debug:false,submitOnce:true,submitButtonID:"submit",
        onError:function(msg, obj, errorlist) {

        },
        onSuccess:function(){
            $(".errormsg").html('');
            var settext = "&id186=" + $("[name=id186]").val();
            settext = settext.replace(/\#/g, "%23");
            submitform(modules["set_data"],settext);
        }
    });
    $("#id186").formValidator({
        onFocus:""
    }).regexValidator({
        regExp:regexEnum.notempty,
        onError:errmsg.Info3
    });


    var nonames = new Array('cgpw', 'id912', 'id913', 'id0', 'id911', 'id51', 'id50');

    var adminPwDif =msg.adminPwDif;
    var oprPwDif = msg.oprPwDif;
    var success1 = msg.submitSuccess;
    var success2 = msg.restartSuccess;
    var cannotModify = msg.cannotModify1;
    var  sameError = msg.pwSameError;
    $(document).ready(function(){
        var sendtext = "&id=186";
        DataRequest("get_json",sendtext,function(data){
            updatecfgvalue("id186",data["id186"]);
        });

        $("[name=id911]").click(function () {
            $(".errormsg").html('');
            var pw1 = $("[name=id51]").val();
            var pw2 = $("#confirmpwd").val();
            if (pw1 != pw2) {
                //  show_message("err",adminPwDif);
                alert(adminPwDif);
                return false;
            } else {
                if (pw1 == "" && pw2 == "") {
                    if (confirm(changepassword.help1)) {
                        admin();
                        setvalues();
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    admin();
                    setvalues();
                }
            }
        });

        $("[name=id912]").click(function () {
            $(".errormsg").html('');
            var pw1 = $("[name=id50]").val();
            var pw2 = $("#confirmopt").val();
            if (pw1 != pw2) {
                // show_message("err",oprPwDif);
                alert(oprPwDif);
                return false;
            } else {
                oprator();
                setvalues();
            }
        });

    });


function admin() {
    $(":input").each(function () {
        if (checkname($(this).attr('name')) || ($("[name=id51]").attr('name')) && ($(this).attr('name') != 'id911')) {
            var sendvalue = $.trim($("[name=id51]").val());
            var sendname = "id51";
            settext = "&" + sendname + "=" + sendvalue;
        }
    });
}

function oprator() {
    $(":input").each(function () {
        if (checkname($(this).attr('name')) || ($("[name=id51]").attr('name')) && ($(this).attr('name') != 'id912')) {
            var sendname = "id50";
            settext = "&" + sendname + "=" + $.trim($("[name=id50]").val());
        }
    });
}

function setvalues() {
    $.ajax({
        type: "POST",
        url: '/xml?method=gw.account.change' + settext + "&tmp=" + Math.random(),
        dataType: "xml",
        error: function (xml) {
            $(xml).find('Error').each(function () {
                var errortext = $(this).attr('msg');
                //show_message("err",errortext);
                alert(errortext);
            });
        },
        success: function (xml) {
            $(xml).find('rsp').each(function () {
                var stat = $(this).attr('stat');
                var admin = $(xml).find('item').attr('value');
                if (stat == "ok") {
                   // show_message("err",success1);
                   alert(success1);
                } else if (stat == "restart" || stat == "reboot") {
                    //show_message("err",success2);
                    alert(success2);
                } else if (stat == "fail") {
                    $(xml).find('Error').each(function () {
                        var code = $(this).attr('code');
                        if (code == 4) {
                           // show_message("err",cannotModify);
                           alert(cannotModify);
                        } else if (code == 5) {
                            gotologin();
                        } else if (code == 8) {
                           // show_message("err",sameError);
                           alert(sameError);
                            var strArray = $(this).attr('msg').split(" ");
                            var mid = strArray[1].substr(2);
                            showerror(mid);
                        } else {
                            var strArray = $(this).attr('msg').split(" ");
                            var mid = strArray[1].substr(2);
                            showerror(mid);
                        }
                    });
                }
            });
        }
    });
}
</script>

